<?php
/**
 * 零起飞-(07FLY-CRM)
 * ==============================================
 * 版权所有 2015-2028   成都零起飞网络，并保留所有权利。
 * 网站地址: http://www.07fly.xyz
 * ----------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ==============================================
 * autor: kfrs <goodkfrs@QQ.com> 574249366
 * Date: 2019-10-3
 */

namespace app\workflow\logic;


/**
 * 审批业务类型=》逻辑层
 */
class WorkflowBusinessType extends WorkflowBase
{
    /**
     * 审批业务类型=>列表
     * @param array $where
     * @param bool $field
     * @param string $order
     * @param int|mixed $paginate
     * @return
     */
    public function getAllList($where = [], $field = true, $order = 'id desc', $paginate = DB_LIST_ROWS)
    {
        $list = $this->modelWorkflowBusinessType->getList($where, $field, $order, $paginate)->toArray();
        return $list;
    }


    /**
     * 添加
     * @param array $data
     * @return array
     */
    public function setAdd($data = [])
    {

        $validate_result = $this->validateWorkflowBusinessType->scene('add')->check($data);
        if (!$validate_result) {
            return [RESULT_ERROR, $this->validateWorkflowBusinessType->getError()];
        }
        $data['create_user_id']=SYS_USER_ID;
        $result = $this->modelWorkflowBusinessType->setInfo($data);

        $result && action_log('新增', '新增workflowBusinessType：' . $data['name']);
        $url = url('show');
        return $result ? [RESULT_SUCCESS, '添加成功', $url] : [RESULT_ERROR, $this->modelWorkflowBusinessType->getError()];
    }

    /**
     * 编辑
     * @param array $data
     * @return array
     */
    public function setEdit($data = [])
    {

        $validate_result = $this->validateWorkflowBusinessType->scene('edit')->check($data);
        if (!$validate_result) {
            return [RESULT_ERROR, $this->validateWorkflowBusinessType->getError()];
        }
        $result = $this->modelWorkflowBusinessType->setInfo($data);

        $url = url('show');
        $result && action_log('编辑', '编辑workflowBusinessType，name：' . $data['name']);
        return $result ? [RESULT_SUCCESS, '编辑成功', $url] : [RESULT_ERROR, $this->modelWorkflowBusinessType->getError()];
    }

    /**
     * workflow删除
     * @param array $where
     * @return array
     */
    public function setDel($where = [])
    {

        $result = $this->modelWorkflowBusinessType->deleteInfo($where,true);

        $result && action_log('删除', '删除workflowBusinessType，where：' . http_build_query($where));

        return $result ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelWorkflowBusinessType->getError()];
    }

    /** 一条信息
     * @param array $where
     * @param bool $field
     * @return
     */
    public function getOne($where = [], $field = true)
    {
        return $this->modelWorkflowBusinessType->getInfo($where, $field);
    }


    /**
     * 获取列表搜索条件
     */
    public function getWhere($data = [])
    {

        $where = [];
        //关键字查
        !empty($data['keywords']) && $where['name|business_type'] = ['like', '%' . $data['keywords'] . '%'];

        return $where;
    }




}
